package com.lfnyxy.service.imp;

import com.lfnyxy.dao.RedListDao;
import com.lfnyxy.entity.RedListEntity;
import com.lfnyxy.query.RedListQuery;
import com.lfnyxy.service.RedListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RedListServiceImp implements RedListService {
    @Autowired
    public RedListDao redListDao;

    public int CreateItem(RedListEntity entity) {
        if (entity != null) {
            return redListDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(RedListEntity entity) {
        if (entity != null) {
            return redListDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List <RedListEntity> QueryPageList(RedListQuery query) {
        int count = redListDao.QueryPageListCount(query);
        query.setTotal(count);
        return redListDao.QueryPageList(query);
    }

    public List <RedListEntity> QueryAll() {
        return redListDao.QueryAll();
    }

    public RedListEntity QueryItem(int Id) {
        if (Id > 0) {
            return redListDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return redListDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(RedListEntity entity) {
        if (entity != null) {
            return redListDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}